home *** CD-ROM | disk | FTP | other *** search
/ Sun Solutions 1997 April to September / Sun Solutions CD - APR '97 - SEP '97 (704-3778-12 Rev. H)(Sun Microsystems, Inc.)(1997).iso / products / .wais / Solaris_2 / old.pl < prev    next >
Text File  |  1995-08-22  |  7KB  |  319 lines

  1. #
  2. # makedesc.pl
  3. #
  4. # Generate The Wais Tree
  5. #
  6. # Copyright Creative Dynamics, Inc. 1995
  7. #
  8. #$dirn = $0;
  9. #$dirn =~ s#(.*)/.*$#$1#;
  10. #require "$dirn/common.pl";
  11.  
  12. $CATDB_NAME = "catalyst";
  13. $USER = "miadmin";
  14.  
  15. #
  16. # use the libmi stuff
  17. #
  18.  
  19. use Mi;
  20.  
  21. $lastCategory = "";
  22. $lastSubCategory = "";
  23.  
  24. ### Set up output directory
  25.  
  26. $outputDirectory = "/tmp/wais-src";
  27. umask(022);
  28. mkdir($outputDirectory, 0777);        # make an output directory for book    chdir "$outputDirectory" || die "Can't cd to $outputDirectory\n";
  29. #unlink(<*>);                # delete all existing files in the t directory
  30. system 'rm -rf *';
  31.  
  32. {
  33.    local($query,$num_col, @record);
  34.    local($db, $row_desc, $result, $row, $col, $row_num, $error);
  35.  
  36. ### the query
  37.  
  38. $query = "
  39. select  p.Product_id, p.SolCompatible,    
  40.     p.ProdCatName, p.ProdSubCat, p.ProdName, v.VendorName,
  41.     p.ProdShortDesc, p.ProdLongDesc,
  42.     p.ProdHomePage, p.ProdImage, p.SrcAvail, p.ProdSrcLang,
  43.     p.ProdSpecHand,
  44.     v.VendorAddr1, v.VendorAddr2, v.VendorAddr3, v.VendorCity,
  45.     v.VendorPostCode,
  46.     v.VendorState, v.VendorZip, v.VendorCountry,
  47.     v.VendorPhone1code, v.VendorPhone1,
  48.     v.VendorPhone2code, v.VendorPhone2,
  49.     v.VendorFaxCode, v.VendorFax,
  50.     v.VendorEmailCode, v.VendorEmail,
  51.     v.VendorURL
  52. from   Vendor v using(lock=table),
  53.        Assoc_ProdVend a using(lock=table),
  54.        Products p using(lock=table)
  55. where  a.ProdId = p.Product_id
  56. and    a.VendId = v.Vendor_id
  57. and    p.Product_id < 200
  58. order by p.ProdCatName, p.ProdSubCat, p.ProdName
  59. ;";
  60.  
  61. # where  p.Product_id < 50 -- use to limit
  62. # alternate order: order by p.ProdCatName, p.ProdSubCat, p.ProdName, v.VendorName
  63.  
  64. ### query the database
  65.  
  66.    ($db = Mi::open("$CATDB_NAME", "$USER", "") ) || die "Can't open Illustra database\n";
  67.  
  68.    (Mi::exec($db, "$query", 0) == 0) || die "Can't exec Illustra query\n";
  69.  
  70.    print "  Query Sent\n";
  71.  
  72.    (($result = Mi::get_result($db)) == 1) || die "Got bad result from Illustra\n";
  73.  
  74.    print "  Got Results\n";
  75.  
  76.    ($row_desc = Mi::get_row_desc_without_row($db)) || die "Error on row description \n";
  77.  
  78.    $num_col = Mi::column_count($row_desc);
  79.  
  80.    print "  Results Have $num_col Columns\n";
  81.  
  82.    $row_num = 0;
  83.    while ($row = Mi::next_row($db, \$error))
  84.    {
  85.     $row_num++;
  86.     print "   Processing row $row_num...\r";
  87.     foreach $col (0..$num_col-1)
  88.     {
  89.           Mi::value($row, $col, $colval, $retlen);
  90.           $record[$col] = $colval;
  91.     }
  92.  
  93. ### Fix the data
  94.  
  95. # map double occurrences of ' to single '
  96.  
  97.     foreach $count (2..12)
  98.     {
  99.         $record[$count] =~ s/\'\'/\'/g;
  100.     }
  101.  
  102. ### Trim trailing spaces
  103.     foreach $count (2..30)
  104.     {
  105.         $record[$count] =~ s/ *$//g;
  106.     }
  107.  
  108. ### Fix descriptions
  109.     if ($record[7] eq "")
  110.     {
  111.         $record[7] = $record[6];
  112.     }
  113.     &makeBullets();
  114.  
  115. ### Now print out the data for this product        
  116.  
  117.     $newchapter = 0;    # not new chapter default
  118.     if ($lastCategory ne $record[2])
  119.     {
  120.         if ($lastCategory ne "")
  121.         {
  122.             chdir "../.." ||  die "Can't cd to ../..\n";
  123.         }
  124.         $newchapter = 1;
  125.         $outputChapterName = $record[2];
  126.         $outputChapterName =~ s/ /_/g;
  127.         $outputChapterName =~ s/\//-/g;
  128.         $outputChapterName = substr($outputChapterName, 0, 25);
  129.         mkdir($outputChapterName, 0777);
  130.         chdir "$outputChapterName" || die "Can't cd to $outputChapterName\n";
  131.         unlink(<*>);
  132.         if ($lastCategory ne "")
  133.                 {
  134.             addsubTOCtail();
  135.             close subTOC;
  136.                 }
  137.         $lastCategory = $record[2];
  138.         $subTOCname = $outputChapterName . ".html";
  139.         open(subTOC, "> $subTOCname");
  140.         &addsubTOCheader($record[2]);
  141.     }
  142.     if ($lastSubCategory ne $record[3])
  143.     {
  144.         if ($newchapter eq 0)
  145.         {
  146.             &makeTOCtail();
  147.             close TOC;
  148.             chdir ".." || die "Can't cd to ..\n";
  149.         }
  150.         $outputSubchapterName = $record[3];
  151.         $outputSubchapterName =~ s/ /_/g;
  152.         $outputSubchapterName =~ s/\//-/g;
  153.         $outputSubchapterName = substr($outputSubchapterName, 0, 25);
  154.         mkdir($outputSubchapterName, 0777);
  155.         chdir "$outputSubchapterName" || die "Can't cd to terName\n";
  156.         unlink(<*>);
  157.         $lastSubCategory = $record[3];
  158.         $TOCname = $outputSubchapterName . ".html";
  159.         open(TOC, "> $TOCname"); 
  160.                 &makeTOCheader($subTOCname, $record[2], $record[3]);
  161.                 chdir("..");
  162.                 &addsubTOC($record[2], $record[3], $outputSubchapterName);
  163.                 chdir "$outputSubchapterName";
  164.     }
  165.  
  166.     $filename = $record[4];
  167.     $filename = substr($filename, 0, 25);
  168.     $filename =~ s/ /_/g;
  169.     $filename =~ s/\//-/g;
  170.     $filename .= ".html";
  171.     open(PRODUCT, "> $filename");
  172.     &makeproductheader($record[3], $outputChapterName . ".html");
  173.     &makeproduct();
  174.     &makeproducttail();
  175.     &addTOCinfo($filename, $record[4], $record[5]);
  176.     close PRODUCT;
  177.  
  178. # End of Product
  179.  
  180.    }
  181.  
  182.    &makeTOCtail();
  183.    close TOC;
  184.    close subTOC;
  185.    Mi::close($db);
  186.  
  187.    print "Processed $row_num records\n";
  188. }
  189.  
  190. print "Complete\n";
  191.  
  192.  
  193. #------------------------------------------------------------------
  194. # SUBROUTINES
  195. #------------------------------------------------------------------
  196.  
  197. #------------------------------------------------------------------
  198. # makeproductheader 
  199. #
  200. # subroutine makeproductheader creates header for every product file
  201.  
  202. sub makeproductheader {
  203.  
  204.     local($string) = @_[0];
  205.     local($filename) = @_[1]; 
  206.  
  207.     print PRODUCT <<PRODUCTHEADER;
  208. <html>
  209. <head>
  210. <title>Solaris - $string</title>
  211. </head>
  212. <body>
  213. <A HREF="http://pinatubo/test.html"><IMG SRC="/goto_toc.gif"> Catalyst Catalog Search Page</A> <A HREF=../$filename><IMG SRC="/goto_back.gif"> Sub-category</A>
  214. <HR>
  215. <H2><A NAME=record[3]>"$record[3]"</A></H2>   
  216.  
  217. <HR>
  218. PRODUCTHEADER
  219. }
  220.  
  221. #------------------------------------------------------------------
  222. # makeproduct
  223. #
  224. # subroutine makeproduct creates info for every product file
  225.  
  226. sub makeproduct {
  227.  
  228.     local($source) = "No";
  229.     local($address) = $record[13] . " " . $record[14] . " " . $record[15];
  230.     local($address1) = $record[16] . ", " . $record[17] . $record[18] . " " . $record[19];
  231.     local($spec) = $record[12];
  232.     local($phone) = "";
  233.     local($phone1) = "";
  234.     local($fax) = "";
  235.     local($email) = "";
  236.     local($url) = "";
  237.     if ($record[22] ne "")
  238.     {
  239.         $phone = "Phone:  " . $record[21] . $record[22];
  240.         $phone1 = $record[23] . $record[24];
  241.     }
  242.     if ($record[26] ne "")
  243.     {
  244.         $fax = "Fax:    " . $record[25] . $record[26];
  245.     }
  246.     if ($record[28] ne "")
  247.     {
  248.         $email = "Email:  " . $record[27] . $record[28];
  249.     }
  250.     if ($record[29] ne "")
  251.     {
  252.         $url = "Url:    " . $record[29];
  253.     }
  254.     $address =~ s/^//g;
  255.     $address1 =~ s/^//g;
  256.     $spec =~ s/\[//g;
  257.     $spec =~ s/]//g;
  258.     $spec =~ s/^ * //g;
  259.     $spec =~ s/^,//g;
  260.     if ($spec eq "")
  261.     {
  262.         $spec = "None.";
  263.     }
  264.  
  265.     if ($phone1 ne "")
  266.     {
  267.         $phone .= "\n        " . $phone1;
  268.     }
  269.  
  270.     if ($record[10] eq "t" or $record[10] eq "T")
  271.     {
  272.     $source = "Yes";
  273.     }
  274.     print PRODUCT <<MAKEPRODUCT
  275. <H3><A NAME=$record[4]>$record[4]</A></H3>
  276. <H4><A NAME=$record[5]>$record[5]</A></H4>
  277. $record[7]<p>
  278. Language: $record[11]<BR>
  279. Source Avail: $source<BR>
  280. Product Special Handling: $spec<BR>
  281. <HR>
  282. <PRE>
  283. <B>$record[5]</B>
  284. $address
  285. $address1
  286. $record[20]
  287. $phone
  288. $fax
  289. $email
  290. $url
  291. </PRE>
  292. MAKEPRODUCT
  293. }
  294.  
  295. #------------------------------------------------------------------ 
  296. # makeproducttail
  297. # subroutine makeproducttail creates tail for product file
  298.   
  299. sub makeproducttail {
  300.  
  301.     print PRODUCT <<MAKEPRODUCTTAIL 
  302. </body>
  303. </html>
  304. MAKEPRODUCTTAIL
  305.   
  306.  
  307. #------------------------------------------------------------------
  308. # makeTOCheader
  309. #
  310. # subroutine MakeTOCheader prints header for each TOC
  311.  
  312. sub makeTOCheader {
  313.  
  314.     local($filename) = @_[0];
  315.     local($category) = @_[1];
  316.  
  317.